package model;

import java.util.Random;

/**
 * @author tymoshya
 * @since 20.08.12
 */
public class Cell {

    private static Random random = new Random();

    public static Cell random(int maxI, int maxJ) {
        return new Cell(random.nextInt(maxI), random.nextInt(maxJ));
    }

    public static Cell at(int x, int y) {
        return new Cell(x, y);
    }

    public static boolean onTheSameDiagonal(Cell cell1, Cell cell2) {
        return Math.abs(cell1.getI() - cell2.getI()) == Math.abs(cell1.getJ() - cell2.getJ());
    }

    private int i, j;

    public Cell(int i, int j) {
        this.i = i;
        this.j = j;
    }

    public int getI() {
        return i;
    }

    public int getJ() {
        return j;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof Cell)) return false;

        Cell cell = (Cell) o;

        if (i != cell.i) return false;
        if (j != cell.j) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = i;
        result = 31 * result + j;
        return result;
    }

    @Override
    public String toString() {
        return "Cell(" + i + ", " + j + ")";
    }
}
